package response_model

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type Response struct {
	Code int    `json:"code"`
	Data any    `json:"data"`
	Msg  string `json:"msg"`
}

func OK(c *gin.Context, data any) {
	c.JSON(http.StatusOK, Response{
		Code: 200,
		Data: data,
		Msg:  "操作成功",
	})
}

func ParameterError(c *gin.Context) {
	c.JSON(http.StatusOK, Response{
		Code: 500,
		Data: nil,
		Msg:  "参数错误",
	})
}

func FailWithMsg(c *gin.Context, msg string) {
	c.JSON(http.StatusOK, Response{
		Code: 500,
		Data: nil,
		Msg:  msg,
	})
}
func FailWithData(c *gin.Context, err error) {
	c.JSON(http.StatusOK, gin.H{
		"code": 500,
		"err":  err,
		"msg":  "操作失败",
	})
}
